//
//  UnarmedListCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2022/12/30.
//

import Foundation
import UIKit

class UnarmedListCell: UITableViewCell {
    let titleL = UILabel()
    
    let baseV = UIView()
    
    let hadCountL = UILabel()
    let unhadCountL = UILabel()
    let delayCountL = UILabel()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .default, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withModal modal: AlarmCbfdeptsListpModal) {
//        let isZJ = modal.sfczzj == "1"
//
//        baseV.isHidden = !isZJ
//
//        if isZJ {
//            baseV.snp.remakeConstraints { make in
//                make.top.equalTo(titleL.snp.bottom).offset(10)
//                make.left.equalTo(titleL.snp.left)
//                make.right.equalTo(arrowIV.snp.left).offset(-10)
//                make.bottom.equalToSuperview().offset(-16)
//                make.height.equalTo(20)
//            }
//        } else {
//            baseV.snp.remakeConstraints { make in
//                make.top.equalTo(titleL.snp.bottom)
//                make.bottom.equalToSuperview().offset(-16)
//                make.height.equalTo(0)
//            }
//        }
        
        titleL.text = modal.label
        hadCountL.text = "\(modal.ybfTotal ?? 0)"
        unhadCountL.text = "\(modal.unbfTotal ?? 0)"
        delayCountL.text = modal.ycbfTotal
    }
    
    func setupUI() {
        titleL.textColor = .hex("#333333")
        titleL.font = .systemFont(ofSize: 17)
        addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(12)
            make.left.equalToSuperview().offset(16)
            make.height.equalTo(20)
        }
        
        addSubview(arrowIV)
        arrowIV.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
        }
        
        addSubview(baseV)
        baseV.snp.makeConstraints { make in
            make.top.equalTo(titleL.snp.bottom).offset(10)
            make.left.equalTo(titleL.snp.left)
            make.right.equalTo(arrowIV.snp.left).offset(-10)
            make.bottom.equalToSuperview().offset(-16)
            make.height.equalTo(20)
        }
        
        let hadKeyL = createLabel(withColor: .hex("#0F499E"))
        hadKeyL.text = "已"
        baseV.addSubview(hadKeyL)
        hadKeyL.snp.makeConstraints { make in
            make.top.equalToSuperview()
            make.width.height.equalTo(16)
            make.left.equalToSuperview()
        }
        
        hadCountL.textColor = .hex("#333333")
        hadCountL.font = .systemFont(ofSize: 15)
        baseV.addSubview(hadCountL)
        hadCountL.snp.makeConstraints { make in
            make.centerY.equalTo(hadKeyL.snp.centerY)
            make.width.equalTo(80)
            make.left.equalTo(hadKeyL.snp.right).offset(8)
        }

        let unHadKeyL = createLabel(withColor: .hex("#FF002A"))
        unHadKeyL.text = "未"
        baseV.addSubview(unHadKeyL)
        unHadKeyL.snp.makeConstraints { make in
            make.centerY.equalTo(hadKeyL.snp.centerY)
            make.width.height.equalTo(16)
            make.left.equalTo(hadCountL.snp.right).offset(8)
        }
        
        unhadCountL.textColor = .hex("#333333")
        unhadCountL.font = .systemFont(ofSize: 15)
        baseV.addSubview(unhadCountL)
        unhadCountL.snp.makeConstraints { make in
            make.centerY.equalTo(hadKeyL.snp.centerY)
            make.width.equalTo(80)
            make.left.equalTo(unHadKeyL.snp.right).offset(8)
        }
        
//        let delayKeyL = createLabel(withColor: .hex("#1E6C00"))
//        delayKeyL.text = "延"
//        baseV.addSubview(delayKeyL)
//        delayKeyL.snp.makeConstraints { make in
//            make.centerY.equalTo(hadKeyL.snp.centerY)
//            make.width.height.equalTo(16)
//            make.left.equalTo(unhadCountL.snp.right).offset(8)
//        }
//
//        delayCountL.textColor = .hex("#333333")
//        delayCountL.font = .systemFont(ofSize: 15)
//        baseV.addSubview(delayCountL)
//        delayCountL.snp.makeConstraints { make in
//            make.centerY.equalTo(hadKeyL.snp.centerY)
//            make.width.equalTo(80)
//            make.left.equalTo(delayKeyL.snp.right).offset(8)
//        }
        
        addSubview(line)
        line.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalTo(arrowIV.snp.right)
            make.height.equalTo(0.5)
        }
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        if highlighted {
            backgroundColor = .hex("#ECECEC")
        } else {
            backgroundColor = .white
        }
    }
    
    func createLabel(withColor color: UIColor) -> UILabel {
        let l = UILabel()
        l.textColor = color
        l.font = .systemFont(ofSize: 12)
        l.layer.borderColor = color.cgColor
        l.layer.borderWidth = 0.5
        l.layer.cornerRadius = 3
        l.layer.masksToBounds = true
        l.textAlignment = .center
        return l
    }
    
    lazy var arrowIV: UIImageView = {
        let iv = UIImageView(image: UIImage(systemName: "chevron.right"))
        iv.tintColor = .hex("#A5A5A5")
        iv.contentMode = .scaleAspectFit
        return iv
    }()
    
    lazy var line: UIView = {
        let li = UIView()
        li.backgroundColor = .hex("#F3F3F3")
        return li
    }()
}
